/*
  * Mirante Tecnologia
  * Copyright 2010, Mirante Informatica LTDA, 
  * and individual contributors as indicated by the @authors tag
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
package com.miranteinfo.seam.facelets.util.input;

import javax.faces.component.UIComponent;

/**
 * Suporte a utilizacao da tag de data.
 * 
 * @author lucas lins
 *
 */
public final class InputDateTag {

	public static final String PATTERN_ATTR = "pattern";
	
	private static final String[] alowedPatterns = {"dd/MM/yyyy","MM/dd/yyyy","MM/yyyy/dd","yyyy/MM/dd","yyyy/dd/MM","dd/yyyy/MM"};
	
	// PUBLIC METHODS *********************
	
	public static String getPattern(UIComponent component){
		if(component != null && component.getAttributes() != null){
			return getPattern(component.getAttributes().get(PATTERN_ATTR));
		}
		return alowedPatterns[0];
	}
	
	public static String getPattern(Object pattern){
		
		if(pattern != null){
			String patternStr = String.valueOf(pattern);
			for(String p : alowedPatterns){
				if(p.equals(patternStr)){
					return p;
				}
			}
		}
		
		return alowedPatterns[0];
	}
	
}
